--
-- Author: ping.wang
-- Date: 2018-07-11 11:15:36
--
-- AuctionBuyOrSellView
--
local AuctionBidBuyRender = import(".renders.AuctionBidBuyRender")
local AuctionNormalBuyRender = import(".renders.AuctionNormalBuyRender")
local AuctionBidSellRender = import(".renders.AuctionBidSellRender")
local AuctionNormalSellRender = import(".renders.AuctionNormalSellRender")
local IconRender = require("app.widget.renders.IconRender")
local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.AuctionBuyOrSellScene

function ClassRef:init()
    display.setCascadeOpacityEnabled(self._root, true)
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)

    self._icon = IconRender.create(self._ui.icon)
    self._icon:setTipEnable(true)

    self._buy1 = AuctionNormalBuyRender.create(self._ui.Node_buy_1)
    self._buy2 = AuctionBidBuyRender.create(self._ui.Node_buy_2)
    self._sell1 = AuctionNormalSellRender.create(self._ui.Node_sell_1)
    self._sell2 = AuctionBidSellRender.create(self._ui.Node_sell_2)

end

--iconrender , 部位名称, 是否是购买界面
function ClassRef:refreshContent(data, isBuy)
    --dump(render:getData())
    local itemData = data.itemData
    self._ui.name:setString(itemData:getName(true))
    self._ui.name:setTextColor( Enums.QualityColor[ itemData:getQuality() ] )
    if itemData.itemBagType == Enums.ItemBagType.equip then
        self._ui.type:setString(itemData:getUserShow() .. itemData:getPosName())
    else
        self._ui.type:setString(itemData:getTypeName())
    end

    self._sell1:setVisible(false)
    self._sell2:setVisible(false)
    self._buy1:setVisible(false)
    self._buy2:setVisible(false)

    local acType = itemData:getAcType()
    local curShowRender
    if isBuy then
        if acType == 1 then
            curShowRender = self._buy1
        elseif acType == 2 then
            curShowRender = self._buy2
        end
    else
        if acType == 1 then
            curShowRender = self._sell1
        elseif acType == 2 then
            curShowRender = self._sell2
        end
    end

    self._icon:setData(itemData)
    self._icon:setNumBgVisible(false)
    if curShowRender then
        curShowRender:setData(data)
    end
end

function ClassRef:onOperate(cb)
	self._onOperate = cb
	self._buy1:onBtnClick(cb)
	self._buy2:onBtnClick(cb)
	self._sell1:onBtnClick(cb)
	self._sell2:onBtnClick(cb)
end

return ClassRef
